from app.auth.models.app_model import AppModel, AppModelCreate
from app.core.handlers.database import SessionDep


class AppModelCRUD:
    def __init__(self, db: SessionDep):
        self.db = db

    async def get_app_model_by_name(self, model_name: str) -> AppModel | None:
        query = self.db.select(AppModel).where(AppModel.model_name == model_name)
        return self.db.scalar(query)

    async def create_app_model(self, app_model_data: AppModelCreate) -> AppModel:
        app_model = AppModel(**app_model_data.model_dump())
        self.db.add(app_model)
        return app_model
